package com.gooapple.notepad.util;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.gooapple.notepad.R;
import com.gooapple.notepad.basic.BasicAdapter;
import com.gooapple.notepad.model.Picture;

public class Gallery3DAdapter extends BasicAdapter {
	private List<Picture> pictures;
	private LayoutInflater inflater;

	public Gallery3DAdapter(List<Picture> pictures, Context context) {
		super();
		this.pictures = pictures;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		if (pictures != null) {
			return pictures.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		return pictures.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.picture_view_item_3d, null);
			viewHolder = new ViewHolder();
			viewHolder.iamge = (ImageView) convertView
					.findViewById(R.id.picture_view);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Bitmap bmp = ImageHelper.fromSDCardToBitmap(pictures.get(position)
				.getPath());
		bmp = ImageHelper.createReflectedImage(bmp);
		viewHolder.iamge.setImageBitmap(bmp);
		convertView.setTag(viewHolder);
		return convertView;
	}

	class ViewHolder {
		ImageView iamge;
	}

}
